package com.wc.codeforces.前缀和与差分.前缀和.Sums_of_Segments;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/29 12:43
 * @description https://codeforces.com/contest/2026/problem/D
 */
public class Main {
    /**
     * 思路：<p>
     * 排列一下 b<p>
     * s[1] - s[0], s[2] - s[0], ... , s[n] - s[0]<p>
     * s[2] - s[1], ... , s[n] - s[1]<p>
     * ...<p>
     * s[n] - s[n - 1]<p>
     */

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 300010;
    static long[] a = new long[N], s = new long[N];
    // sum[i] 表示0 ~ i行的前缀和, rows[i] 表示从 0 ~ i行的个数和
    static long[] sum = new long[N], rows = new long[N];
    // ss 表示 s 的前缀和
    static long[] ss = new long[N];
    static int n, q;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
        for (int i = 1; i <= n; i++) ss[i] = ss[i - 1] + s[i];
        for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + ss[n] - ss[i - 1] - (n - i + 1) * s[i - 1];
        for (int i = 1; i <= n; i++) rows[i] = rows[i - 1] + n - i + 1;
        q = sc.nextInt();
        while (q-- > 0) {
            long l = sc.nextLong(), r = sc.nextLong();
            out.println(get(r) - get(l - 1));
        }
        out.flush();
    }

    static long get(long x) {
        int l = 0, r = n;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (rows[mid] <= x) l = mid;
            else r = mid - 1;
        }
        long res = sum[l];
        x -= rows[l];
        res += ss[l + (int) x] - ss[l] - x * s[l];
        return res;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
